import { TOKEN_KEY } from "@/constants";
import type { Profile } from "@/types/user";
import Cookies from "js-cookie";
import { defineStore } from "pinia";
import { ref } from "vue";

export const useUserStore = defineStore("hm-user", () => {
  const token = ref("");
  // 个人信息
  const profile = ref<Profile>({} as Profile)
  const setProfile = (p: Profile) => {
      profile.value = p
  }
  const setToken = (val: string) => {
    Cookies.set(TOKEN_KEY, val);
  };
  const getToken = () => {
    return Cookies.get(TOKEN_KEY);
  };
  const removeToken = () => {
    return Cookies.remove(TOKEN_KEY);
  };
  return { token, setToken, getToken, removeToken,setProfile,profile };
});
